package com.mszlu.blog.controller;

import com.mszlu.blog.dao.pojo.Category;
import com.mszlu.blog.service.CategoryService;
import com.mszlu.blog.vo.Result;
import com.mszlu.blog.vo.params.CategoryPageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Package: com.mszlu.blog.controller
 * @ClassName: CategoryController
 * @Author: 陈威
 * @CreateTime: 2021/9/3 22:42
 * @Description:
 */
@RestController
@RequestMapping("categorys")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    @GetMapping
    public Result category() {
        return Result.success(categoryService.findCategoryAll());
    }


    //查询所有分类信息
    @GetMapping("detail")
    public Result categoriesDetail() {
        return categoryService.findAllDetail();
    }

    //通过id查询分类信息
    @GetMapping("detail/{id}")
    public Result categoriesDetail(@PathVariable("id") Long id) {
        return categoryService.categoriesDetailById(id);
    }




    @PostMapping("categoryAll")
    public Result getCategoryAll(@RequestBody CategoryPageParam params){
        return categoryService.getCategoryAll(params);
    }

    @PostMapping("deleteCategoryById/{id}")
    public Result deleteCategoryById(@PathVariable("id")Long id){
        return categoryService.deleteCategoryById(id);
    }

    @PostMapping("UpdateCategory")
    public Result UpdateCategoryById(@RequestBody Category category){
        return categoryService.UpdateCategoryById(category);
    }
    @PostMapping("addCategory")
    public Result addCategory(@RequestBody Category category){
        return categoryService.addCategory(category);
    }
}